package org.game.ddd.editor.controller;

import com.alibaba.fastjson.JSON;
import de.felixroske.jfxsupport.FXMLController;
import javafx.beans.property.DoubleProperty;
import javafx.beans.property.ReadOnlyDoubleProperty;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.*;
import javafx.scene.paint.Color;
import lombok.SneakyThrows;
import org.game.ddd.editor.constant.ApiConstant;
import org.game.ddd.editor.model.CellModel;
import org.game.ddd.editor.support.AbstractCellCreate;
import org.springframework.stereotype.Controller;

import java.io.FileInputStream;
import java.net.URL;
import java.util.List;
import java.util.ResourceBundle;

@FXMLController
public class MainController extends AbstractCellCreate implements Initializable {
    @FXML
    public AnchorPane mainPane;

    @SneakyThrows
    @Override
    public void initialize(URL location, ResourceBundle resources) {
        URL url = getClass().getResource("/map/test/info.json");
        FileInputStream fileInputStream = new FileInputStream(url.getFile());

        StringBuffer stringBuffer = new StringBuffer();
        int c = 0;

        while ((c = fileInputStream.read()) != -1) {
            stringBuffer.append((char) c);
        }

        List<CellModel> o = JSON.parseArray(stringBuffer.toString()).toJavaList(CellModel.class);
        List<BorderPane> paneList = createBorderPaneList(o);
        mainPane.getChildren().addAll(paneList);
    }
}
